/**
 * 
 */
package org.androbuzz;

import android.content.Context;
import android.database.Cursor;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CursorAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class AndroBuzzBuzzListAdaptor extends CursorAdapter {

	private final LayoutInflater mInflater;
	
	/**
	 * @param context
	 * @param c
	 */
	public AndroBuzzBuzzListAdaptor(Context context, Cursor c) {
		super(context, c);
		mInflater = LayoutInflater.from(context);
	}

		/* (non-Javadoc)
	 * @see android.widget.CursorAdapter#bindView(android.view.View, android.content.Context, android.database.Cursor)
	 */
	@Override
	public void bindView(View view, Context context, Cursor cursor) {
		TextView tvAuthor = (TextView) view.findViewById(R.id.text1);
		tvAuthor.setText(cursor.getString(cursor.getColumnIndex(AndroBuzzDbAdapter.KEY_AUTHOR_NAME)));
		
		TextView tvDate = (TextView) view.findViewById(R.id.text2);
		tvDate.setText(cursor.getString(cursor.getColumnIndex(AndroBuzzDbAdapter.KEY_DATE)));
		
		TextView tvSummary = (TextView) view.findViewById(R.id.text3);
		tvSummary.setText(cursor.getString(cursor.getColumnIndex(AndroBuzzDbAdapter.KEY_SUMMARY)));
		
		// Enable this once we get picture management
//		ImageView avatar = (ImageView) view.findViewById(R.id.Avatar);
//		int ivID = cursor.getString(cursor.getColumnIndex(AndroBuzzDbAdapter.KEY_AVATAR));
//		String ivUrl = "/sdcard/" + TAG + "cache/pictures/" + ivID;
//		avatar.setImageBitmap(ivUrl);
	}

	/* (non-Javadoc)
	 * @see android.widget.CursorAdapter#newView(android.content.Context, android.database.Cursor, android.view.ViewGroup)
	 */
	@Override
	public View newView(Context context, Cursor cursor, ViewGroup parent) {
		final View view = mInflater.inflate(R.layout.feed_row, parent, false);
		return view;
	}

}
